package com.example.biyesheji.controller;

import com.example.biyesheji.model.param.ProductSaleParam;
import com.example.biyesheji.model.param.Search;
import com.example.biyesheji.model.param.SearchParam;
import com.example.biyesheji.model.result.LayuiPageTable;
import com.example.biyesheji.pojo.ProductSales;
import com.example.biyesheji.service.TableService;
import com.example.biyesheji.utils.LayuiFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class TableController {

    @Autowired
    private TableService tableService;

    @CrossOrigin
    @GetMapping("/tablePage")
    public LayuiPageTable pageTable(ProductSaleParam param){
        param.setPage((param.getPage()-1)*15+1);
        List<ProductSales> pageList = tableService.getPageList(param);
        LayuiPageTable layuiPageTable = LayuiFactory.defaultPageTable(pageList);
        return layuiPageTable;
    }


    @CrossOrigin
    @GetMapping("/tablePage1")
    public LayuiPageTable pageTable1(SearchParam param){
        //param.setPage((param.getPage()-1)*15+1);
        param.setPage((param.getPage()-1)*15+1);
        ProductSaleParam param1 = new ProductSaleParam();
        param1.setPage(param.getPage());
        param1.setLimit(param.getLimit());
        param1.setUserId(param.getSearch().getUserId());
        param1.setSex(param.getSearch().getSex());
        param1.setLocal(param.getSearch().getLocal());
        List<ProductSales> pageList = tableService.getPageList(param1);
        LayuiPageTable layuiPageTable = LayuiFactory.defaultPageTable(pageList);
        return layuiPageTable;
    }


}
